<?php

if (!isset($_COOKIE["checkLoginAdm"])) {
	
	header("Location: index.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/base.php.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="images/favicon.ico" type="image-x-icon"  />
<!-- InstanceBeginEditable name="doctitle" -->
<title>CineBD - A divers&atilde;o espera voc&ecirc;</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="cinebd.js"></script>
<style type="text/css">

	body {
		
		/*background-color:#80CFD8;*/
		background-color:#FFFFFF;
		/*background-image:url(../images/bg_thin.png);
		background-repeat:repeat-x;*/
		font-family:"Courier New", Courier, monospace;
		top:0px;
		margin-top:0px;
		padding:0px;
	} 
	
	a {
		
		text-decoration:none;
		color:#000;
	}
	
	.menu {
		
		color:#000000;
		text-align:center;
		font-size:18px;
		font-family:"Courier New", Courier, monospace;
		//border-bottom: 1px solid #03C ;
	}
	
	.menu:hover {
		
		border: 2px solid #FFF;
		//border-left: 5px solid #FFF;
		//border-bottom: 5px solid #FFF;
		//border-right: 10px solid #fff;
		//background-color: #06F;
	}
	
	.logo {
		width:150px;
		height:150px;
	}
	
	.header {
		background-image:url(images/Template_03.png);
		//background-repeat:repeat-x;
		width:300px;
		height:149px;
		text-align:center;
	}
	
	.sub_header {
		
		background-image:url(images/sub_header.png);
		width:681px;
		height:100px;
		text-align:center;
		font-size:18px;
		font-weight:bold;
		font-family:"Courier New", Courier, monospace;
		
	}
	
	.logout {
		
		font-size:14px;
		color:#FFF;
		
	}
	
	.logout:hover {
		
		border-bottom: 2px solid #FFF;
		
	}
	
	.left_menu {
		
		background-image:url(images/bg_thin.png);
		background-attachment:fixed;
		width:356px;
		height:768px;
		vertical-align:top;
		text-align:center;
	}
	
	.right_menu {
		
		background-image:url(images/bg_thin.png);
		background-attachment:fixed;
		width:355px;
		height:768px;
		vertical-align:top;
		font-size:15px;
		font-family:"Courier New", Courier, monospace;
		text-align:center;
	}
	
	.right_menu_text {
		
		text-align:center;
		font-size:16px;
	}
	
	.right_menu_text:hover {
		
		border-bottom: 2px solid #FFF;
	}
	
	.bottom_bg {
		background-image:url(images/bottom_bg.png);
		background-repeat:y;
	}
	
	.proximas {
		text-align:center;
		font-weight:bold;
		font-size:18px;
	}
	

	.content {
		
		text-align:center;
		vertical-align:text-top;
		font-size:12px;
		font-family:"Courier New", Courier, monospace;
		width:auto;
	}
	
	.linhaSessao {
		background-color:#FF9;
		font-weight:bold;
		text-align:center;
			
	}
	
	.colunaDias {
		background-color:#FF9;	
		font-weight:bold;
	}
	
	.centroTabela {
		background-color:#CC3333;
		color:#FFF;
		font-weight:bold;
	}
	
	.colunaIngressos {
		background-color:#FF9;	
		font-weight:bold;
	}
	
	.centroIngressos {
		font-weight:bold;
		text-align:center;
		
	}

	.ingressosBaratos {
		color:#090;
		font-weight:bold;
		text-align:center;
		
	}
	
	.menu_admin {
		background-image:url(images/square.png);
		background-repeat:no-repeat;
		background-position:left;
		width:10px;
		height:10px;
		
	}
	
	
	
	<!-- TemplateBeginEditable name="css" -->
	
	<!-- TemplateEndEditable -->
</style>
</head>

<body>
<table align="center" cellpadding="0" cellspacing="0" border="0" style="top:0px;margin-top:0px;">
	<tr>
    	<td rowspan="3" class="left_menu">
        	<a href="index.php">
            	<img class="logo" src="images/logo.png" />
            </a>
            <br /> 
            
            <table width="100%" cellpadding="0" cellspacing="8" align="center">
            	<tr>
                	<td>
                    	<span class="menu"><a href="emcartaz.php">&nbsp;EM CARTAZ&nbsp;</a></span>
                    </td>
                 </tr>
                 <tr>
                	<td>
                    	<span class="menu"><a href="quemsomos.php">&nbsp;QUEM SOMOS&nbsp;</a></span>
                    </td>
                 </tr>
                 <tr>
                	<td>
                    	<span class="menu"><a href="faleconosco.php">&nbsp;FALE CONOSCO&nbsp;</a></span>
                    </td>
                 </tr>
                 <tr>
                	<td>
                    	<span class="menu"><a href="ingressos.php">&nbsp;INGRESSOS&nbsp;</a></span>
                    </td>
                 </tr>
                 <tr>
                	<td>
                    	<span class="menu"><a href="#" id="clientes">&nbsp;CLIENTES&nbsp;</a></span>
                        <br />
                        <div id="menu_client" style="text-align:left; font-size:15px; display:none; margin-left:25%;">
                        	<ol style="list-style-type:none;">
                            	<li><a href="login.php">Logar</a></li>
                                <li><a href="cadastro.php">Cadastrar</a></li>                    
                            </ol>
                        </div>
                    </td>
                 </tr>
            </table> 
  		</td>
        <td class="header">
        	<img src="images/header.png" />
        </td>
                
        <td rowspan="3" class="right_menu">
          	<img class="logo" src="images/popcorn.png" style="margin-left:10px"/>
        	<table width="100%" cellpadding="0" cellspacing="8">
            	<tr>
                	<td class="proximas">
                    	PR&Oacute;XIMAS ESTREIAS
                    </td>
                    </tr>
                    <br />
                    <tr>
                    <td>
         
		<?php
				require_once("php/config.php");
				require_once("php/postgres.php");
				
				try {
					
					$confs = $GLOBALS["CONFIGS"]["PSQL_DB"];
					$pgcon = new PostgresConnection($confs["HOST"], $confs["PORT"], $confs["USER"], $confs["PASSWORD"], $confs["DATABASE"]);
            
					$estreias = $pgcon->getAllEstreias();					

                    echo" <table width='100%' cellpadding='0' cellspacing='8' align='center'>";
                        foreach ($estreias as $estreia) {
                    		$nome = $estreia["nome"];
                            echo "<tr>
                                <td>
                                    <span class='right_menu_text'><a href='#' onclick=\"javascript:opensinopse('$nome');\">&nbsp;" . $nome .  "&nbsp;</a></span>
                                </td>
                            </tr>";
             			}
        			echo "</table>					
            </td>
            </tr>          
            </table>
        </td>
    </tr>";    
   
            if (isset($_COOKIE["checkLogin"])){
            
             	echo" <tr> <td class='sub_header'>Ol&aacute;, $_COOKIE[checkLogin]!
                <span class='logout'><a href='logout.php'>Sair</a></span></td></tr>";
                
            } else {
            
            	echo' <td class="sub_header"></td>';
            }
        
 		} catch (PostgresConnectionException $pce) {
            
        echo "<span style='color:red;'>Desculpa, mas sua requisi&ccedil;&atilde;o n&atilde;o pode ser processada agora. Volte mais tarde.</span>";
        }
                    
?>
        
    
    <tr>
    	<td class="content">
        	<!-- InstanceBeginEditable name="content" -->
         <script type="text/javascript">
		 
         function sendForm() {
				
					$("#send_form").attr("disabled", "disabled");
					$("#send_form").val("Enviando...");
					
					var error = false;
					var msg = "";
					
					var mand_field = [
										"nome",
										"nacionalidade",
										"empresa",
										"duracao",
										"categoria",
										"censura",
										"sinopse"
									 ];
									 
					var values = [];
					
					for (field in mand_field) {
					
						var key = mand_field[field];
						values[key] = $("#" + key).val();
						$("#" + key).css("background-color", "white");
						if (values[key] == "") {
							
							error = true;
							$("#" + key).css("background-color", "red");
						}
					}
										
					if (!error) {
						
						$.post("alterMovie.php",
								  {
									  	nome : $("#nome").val(),
										nacionalidade : $("#nacionalidade").val(),
										empresa : $("#empresa").val(),
										duracao : $("#duracao").val(),
										categoria : $("#categoria").val(),
										censura : $("#censura").val(),
										sinopse : $("#sinopse").val(),
										namebefore : $("#namebefore").val(),
								  },
								  function(data) {
									  
									  if (data != 0) {
										
											alert("Houve um erro na alteração do filme.\n" + data);
									  } else {
										
											alert("Filme alterado com sucesso.");
											//$("#cadasform").reset();
											document.forms[0].reset();
											$("#res_pass").html("");
											$("#ver_link").removeData("ok");
											$("#ver_link").css("color", "#00F");
											$("#ver_login").removeData("ok");
											$("#ver_login").css("color", "#00F");
									  }
									  
									  $("#send_form").removeAttr("disabled");
									  $("#send_form").val("OK");
								  });
					} else {
					
						msg += "Verifique os campos em vermelhos";
					}
					
					if (msg != "") {
					
						alert(msg);
					}
					
					$("#send_cadas").removeAttr("disabled");
					$("#send_cadas").val("OK");
				}
								
				$(document).ready(function() {

											$("#send_form").click(sendForm);

										   });
			</script>
        	
            
            
<?php
                
	require_once("php/config.php");
	require_once("php/postgres.php");
	
	try {

		$confs = $GLOBALS["CONFIGS"]["PSQL_DB"];
		$pgcon = new PostgresConnection($confs["HOST"], $confs["PORT"], $confs["USER"], $confs["PASSWORD"], $confs["DATABASE"]);
	          
		$filmes = $pgcon->getAllMovies();
		
		echo '<div style="text-align:left; margin-left:40px;">
            <span class="proximas">EDITAR FILME</span>
            <br />
            <br />
			<form align="left" method="post"><div>
			<select name="movie" id="movie">
			<option value="0" selected>(Escolha o filme)</option>';
						
			foreach ($filmes as $filme){
				
				echo'
						
						<option value="'. $filme["nome"] .'">'. $filme["nome"] .'</option>';
			}

		echo' 
			</select>
			<input type="submit" value="Editar" />
			</form>
			</div>';  
		
		
		if (isset($_POST["movie"])){
			
			$filmep = $pgcon->getAllMovies(array("nome" => $_POST["movie"]));
			$filme = $filmep[0];
                        	  
			echo'<div>
			<br />
            <form id="edit" action="#" onsubmit="return false;">
            	<table cellpadding="0" cellspacing="0" border="0">
                	<tr>
            			<td><span>Nome do Filme: &nbsp;&nbsp;</span></td>
 						<td><input id="nome" name="nome" type="text" size="32" maxlength="50" value="'. $filme['nome'] .'" /></td>
						<td><input name="namebefore" id="namebefore" type="hidden" size="32" maxlength="50" value="'. $filme['nome'] .'"/></td>
                    </tr>
                    <tr>
                		<td><span>Nacionalidade: &nbsp;&nbsp; </span></td>
                        <td><input id="nacionalidade" name="nacionalidade" type="text" size="40" maxlength="100" value="'. $filme['nacionalidade_filme'] .'" /></td>
                    </tr>
                    
                		<td><span>Empresa Produtora: &nbsp;&nbsp; </span></td>
                        <td><input id="empresa" name="empresa" type="text" size="40" maxlength="100" value="'. $filme['empresa_produtora'] .'" /></td>
                    </tr>
                     <tr>
                    	<td><span>Dura&ccedil;&atilde;o: &nbsp;&nbsp;</span></td>
                        <td><input id="duracao" name="duracao" type="text" size="40" maxlength="50" value="'. $filme['duracao_filme'] .'"/></td>
                     </tr>
                </table>

                <table cellpadding="0" cellspacing="0" border="0">
                	<tr>
                    <td><span>Categoria: &nbsp;&nbsp;</span></td>
                        <td><input name="categoria" id="categoria" type="text" size="32" maxlength="50" value="'. $filme['categoria'] .'"/></td>
                         </tr>
                         <tr>
                       	<td valign="top"><span align>Atores: &nbsp;&nbsp;</span></td>';
						echo "<td>";
						foreach($filme['atores'] as $ator){
                        	echo'<br /><input name="atores" id="atores" type="text" size="32" maxlength="50" value="'. $ator .'"/>
							'; 
						}
						echo "</td>";
                echo'</table>
                
                <table cellpadding="0" cellspacing="0" border="0">
                	<tr><br />
                        <td>
                            <span>Censura: &nbsp;&nbsp;&nbsp; <input id="censura" name="censura" type="text" size="32" maxlength="10" value="'. $filme['censura'] .'" /></span>
                        </td>
                    	<td></td>
                    </tr>
                </table>
                <table cellpadding="0" cellspacing="0" border="0">
                	<tr>
                    <span> Sinopse
                <br />
                <textarea id="sinopse" name="sinopse" rows="10" cols="50">'. $filme['sinopse'] .'</textarea>
                <br />
                    </tr>
                    <td><span>Editar Imagem: &nbsp;&nbsp;</span></td>
                        <td><input name="foto" id="foto" type="file" size="25" maxlength="12" value="'. $filme['foto'] .'" /></td>						
                    </tr>
                </table>
                <br  />                
                <input type="button" id="send_form" value="OK" />
            </form>
            </div>';
		}
			
	} catch (PostgresConnectionException $pce) {
		
		echo "<span style='color:red;'>Desculpa, mas sua requisi&ccedil;&atilde;o n&atilde;o pode ser processada agora. Volte mais tarde.</span>";
	}  

?>
            
			<!-- InstanceEndEditable -->
    </tr>    
</table>
</body>
<!-- InstanceEnd --></html>
